/**
 * 实现队列
 * new Queue() .task(()=>{console.log(1)},1000) .task(()=>{console.log(1)},3000) .task(()=>{console.log(1)},1000) .run()
 */
class Queue {
  constructor() {
    this.queue = [];
  }

  task(fn, wait) {
    const qu = () => {
      setTimeout(() => {
        fn();
        this.next();
      }, wait);
    }
    this.queue.push(qu);
    return this;
  }
  
  next() {
    const fn = this.queue.shift();
    fn && fn();
  }

  run() {
    this.next();
  }
}

// 测试-----------------------
new Queue().task(()=>{console.log(10)},1000).task(()=>{console.log(30)},3000).task(()=>{console.log(11)},1000).run();